


<html>

    <head>  

        <link href="<?php echo Yii::app()->request->baseUrl; ?>/css/dropzone.css" type="text/css" rel="stylesheet" />
        <script src="<?php echo Yii::app()->request->baseUrl; ?>/js/dropzone.min.js"></script>

        <script>
            var urlBase = '<?php echo Yii::app()->request->baseUrl; ?>/uploads/album';
            Dropzone.options.myDropzone = {
                init: function() {
                    thisDropzone = this;

                    var album_name = $('#album_name').val();
                    var album_id = $('#album_id').val();
                    
                    $.get('loadImageServer?album_id=' + album_id, function(data) {

                        $.each(data, function(key, value) {

                            var mockFile = {name: value.name, size: value.size};


                            thisDropzone.options.addedfile.call(thisDropzone, mockFile);

                            thisDropzone.options.thumbnail.call(thisDropzone, mockFile, urlBase + "/" + album_id + "/" + value.name);

                        });

                    });
                },
                addRemoveLinks: true,
                removedfile: function(file) {
                    var name = file.name;
                    var album_name = $('#album_name').val();
                    var album_id = $('#album_id').val();
                    $.ajax({
                        type: 'POST',
                        url: 'delImage',
                        data: "path=" + album_id + '/' + name + '&name=' + name,
                        dataType: 'html'
                    });
                    var _ref;
                    return (_ref = file.previewElement) != null ? _ref.parentNode.removeChild(file.previewElement) : void 0;
                }
            };

            function getBaseURL() {
                var url = location.href;  // entire url including querystring - also: window.location.href;
                var baseURL = url.substring(0, url.indexOf('/', 14));


                if (baseURL.indexOf('http://localhost') != -1) {
                    // Base Url for localhost
                    var url = location.href;  // window.location.href;
                    var pathname = location.pathname;  // window.location.pathname;
                    var index1 = url.indexOf(pathname);
                    var index2 = url.indexOf("/", index1 + 1);
                    var baseLocalUrl = url.substr(0, index2);

                    return baseLocalUrl + "/";
                }
                else {
                    // Root Url for domain name
                    return baseURL + "/";
                }

            }
            function goBack() {
                window.history.back()
            }
        </script>


    </head>

    <body>

        <!-- 2 -->
        <button class="btn btn-primary" name="button" style="margin-bottom:5px" type="submit" onclick="goBack()">Back</button>
        <form action="upload" class="dropzone" id="my-dropzone">
            <input id="album_id" name="album_id" type="hidden" value="<?= $album_id; ?>"/>
            <input id="album_name" name="album_name" type="hidden" value="<?= $album_name; ?>"/>
        </form>


    </body>

</html>
